package desktop;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

class ShowTotal extends JFrame {
    ShowTotal(List<Screen> screens, List<ScoreTable> scoreTables){
        JPanel jPanel1 = new JPanel();
        final List<JCheckBox> jCheckBoxes = new ArrayList<>();
        for(int i=1;i<=screens.size();i++){
            JCheckBox jCheckBox = new JCheckBox("赛道"+i);
            jPanel1.add(jCheckBox);
            jCheckBoxes.add(jCheckBox);
        }

        JPanel jPanel2 = new JPanel();
        JButton jButton_all = new JButton("全选");
        jButton_all.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for(JCheckBox jCheckBox:jCheckBoxes)
                    jCheckBox.setSelected(true);
            }
        });
        JButton jButton_notAll = new JButton("全不选");
        jButton_notAll.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for(JCheckBox jCheckBox:jCheckBoxes)
                    jCheckBox.setSelected(false);
            }
        });
        JButton jButton = new JButton("确定");
        jButton.setBackground(Color.GREEN);
        final JFrame jFrame_this = this;
        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for(int i=0;i<jCheckBoxes.size();i++){
                    if(jCheckBoxes.get(i).isSelected()){
                        screens.get(i).showTotalScore();
                        scoreTables.get(i).showTotal();
                    }
                }
                jFrame_this.setVisible(false);
            }
        });
        jPanel2.add(jButton_all);
        jPanel2.add(jButton_notAll);
        jPanel2.add(jButton);

        this.setLayout(new GridLayout(2,1));
        this.add(jPanel1);
        this.add(jPanel2);
        this.setTitle("显示总分");
        this.setSize(250,150);
        this.setResizable(false);
        this.setVisible(true);
    }
}
